<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *公告管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list' || $_RQ['op']=='list2' || $_RQ['op']=='list3'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1);
	if($_RQ['op']=='list'){
		$params['type']=array(0);
	}elseif($_RQ['op']=='list3'){
		$params['type']=array(1);
	}else{
		$params['type']=array(3);
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 100;
	$total='';
	$fields=array('id','uniacid','title','type','status');
	$list=pdo_getslice('jy_yxw_store',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		$nowyue = mktime(0,0,0,date('m'),1,date('Y'));
		$yesyue = mktime(0,0,0,date('m')-1,1,date('Y'));
		$params=array('uniacid'=>$_SESSION['uniacid']);
		if($_RQ['jiao_time']){
			$time_range=cfc('tools')->base64_decode($_RQ['jiao_time'],$_SESSION['base_key_str']);
			$time_range=json_decode($time_range,true);
			$return['params']['jiao_time']=$time_range;
			$params['jiao_time between']=array($time_range['tstart'],$time_range['tend']);
		}
		$heparams=$params;
		foreach($list as &$item){
			$item=$this->model('count')->inall($item,$params,$heparams);
		}
	}
	paixu($list,'allfee','desc');
	foreach($list as $k=>&$lv){
		$lv['rank']=$k+1;
	}
	$heji=array('title'=>'合计');
	foreach($list as $v){
		$heji['fee2'] +=$v['fee2'];
		$heji['fee1'] +=$v['fee1'];
		$heji['bufee'] +=$v['bufee'];
		$heji['fee5'] +=$v['fee5'];
		$heji['fee4'] +=$v['fee4'];
		$heji['fee3'] +=$v['fee3'];
		$heji['allfee'] +=$v['allfee'];
		$heji['shouhoufee'] +=$v['shouhoufee'];
		$heji['zufee'] +=$v['zufee'];
		$heji['peifee'] +=$v['peifee'];
		$heji['now'] +=$v['now'];
		$heji['yes'] +=$v['yes'];
	}
	$heji['fee2']=price($heji['fee2'],'int');
	$heji['fee1']=price($heji['fee1'],'int');
	$heji['tuiinfee']=price($heji['tuiinfee'],'int');
	$heji['shouhoufee']=price($heji['shouhoufee'],'int');
	$heji['zufee']=price($heji['zufee'],'int');
	$heji['fee5']=price($heji['fee5'],'int');
	$heji['fee4']=price($heji['fee3'],'int');
	$heji['fee3']=price($heji['fee3'],'int');
	$heji['now']=price($heji['now'],'int');
	$heji['allfee']=price($heji['allfee'],'int');
	$heji['yes']=price($heji['yes'],'int');
	$list[]=$heji;
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',		
		'list'=>array('data'=>'list','delall'=>false,'del_one'=>false,'edit'=>false,'list'=>array(
			array('name'=>'rank','title'=>'排名','type'=>'string'),
			array('name'=>'title','title'=>'门店','type'=>'string'),
			array('name'=>'fee2','title'=>'定金','type'=>'string'),
			array('name'=>'fee1','title'=>'成交费','type'=>'string'),
			array('name'=>'tuiinfee','title'=>'退款收费','type'=>'string'),
			array('name'=>'fee3','title'=>'分期缴费','type'=>'string'),
			array('name'=>'zufee','title'=>'补贴费','type'=>'string'),
			array('name'=>'fee5','title'=>'退定金','type'=>'string'),
			array('name'=>'fee4','title'=>'退单费','type'=>'string'),
			array('name'=>'now','title'=>'销售业绩','type'=>'string'),
			array('name'=>'shouhoufee','title'=>'售后成本','type'=>'string'),
			array('name'=>'allfee','title'=>'实收合计','type'=>'string'),
			array('name'=>'yes','title'=>'上月业绩','type'=>'string'),
		)),
		'search'=>array(
			array('name'=>'jiao_time','width'=>10,'title'=>'交费日期','type'=>'time_range'),
		)
	);
	$return['store']=pdo_getall('jy_yxw_store',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
	$return['htmls']=$htmls;
	exi($return);
}
